package controllers;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.*;

import models.SolutionAdoption;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

@SuppressWarnings("serial")
public class ajxRemoveAdoptionSolutionServlet extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/xml");
		PrintWriter out = resp.getWriter();
		
		String AdoptID = req.getParameter("adopt_id");
		if ( AdoptID == null ){
			resp.sendRedirect("/home.jsp?error=Solution Adoption id is null.");
		}
		Long lAdoptID = Long.parseLong(AdoptID);
		
		Objectify ofy = ObjectifyService.begin();
   		Query<SolutionAdoption> q = ofy.query(SolutionAdoption.class).filter("adoptID", lAdoptID);   		
   		for ( SolutionAdoption f : q.fetch() ) {
   			ofy.delete(f);
   		}

		String SolID = req.getParameter("sol_id");
		if ( SolID == null ){
			resp.sendRedirect("/home.jsp?error=Solution id is null.");
		}
		Long lSolID = Long.parseLong(SolID);
   		
		AdoptionConnect ADT = new AdoptionConnect();
		List<HashMap<String,Object>> rs = ADT.getQuery("solID", lSolID);
		if ( rs == null )
			resp.sendRedirect("/home.jsp");		
		
		
		String easyRankDesc =  "";
		String achievedTypeDesc =  "";
		for(int i = 0 ; i < rs.size() ;i++){

			out.println("<TABLE><TBODY><TR><TD><BR></TD></TR><TR><TD width=525><TABLE width=525><TBODY></TBODY></TABLE>");
			out.println("<TABLE width=525><TBODY><TR>");
			out.println("<TD width=120>Solution Team lead :</TD>");
			out.println("<TD width=405><DIV style='COLOR: black;' id=1>" + rs.get(i).get("adptTeamLead") + "</DIV></TD></TR></TBODY></TABLE>");

			out.println("<TABLE width=575><TBODY><TR>");
			out.println("<TD width=275>Location : " + rs.get(i).get("Location") + "</TD>");			
			out.println("<TD width=250>Customer : " + rs.get(i).get("Customer") + "</TD>");
			out.println("<TD width=50><INPUT id=" + rs.get(i).get("adoptID") + " class=lotusBtn onclick=javascript:removeAdopt(" + rs.get(i).get("adoptID") + "," + rs.get(i).get("solID") + ") value=Remove type=button></TD>");
			out.println("</TR></TBODY></TABLE></TR></TBODY></TABLE>");
			
			out.println("<TABLE width=525 height=15><TBODY><TR bgColor=#a2a1a6>");
			out.println("<TD>Process</TD>");
			out.println("<TD>Primary Benefit</TD>");
			out.println("<TD>Benefit Results</TD>");
			out.println("<TD>Days to Implement</TD>");
			out.println("<TD>Adopted Feedback</TD>");
			out.println("<TD>Date Implemented</TD></TR><TR bgColor=#ebf1d5>");
			
			out.println("<TD width=75>" + rs.get(i).get("processArea") + "</TD>");
			
			easyRankDesc = (String) rs.get(i).get("easyRankDesc");			
			out.println("<TD width=100>" + easyRankDesc + "</TD>");
			out.println("<TD width=75>" + rs.get(i).get("achievedValue") + "&nbsp;" + rs.get(i).get("achievedUnits") + "</TD>");
			out.println("<TD width=75>" + rs.get(i).get("impDays") + "</TD>");
			
			achievedTypeDesc = (String) rs.get(i).get("achievedTypeDesc");
			out.println("<TD width=100>" + achievedTypeDesc + "</TD>");
			out.println("<TD width=100>" + rs.get(i).get("dtImplemented") + "</TD></TR></TBODY></TABLE>");
			
			out.println("<TABLE width=525><TBODY><TR><TD width=275><B>Continuous Improvement Comments: </B></TD></TR><TR>");
			out.println("<TD width=275></TD></TR></TBODY></TABLE><DIV style='BORDER-BOTTOM: #cccccc 2px solid; BORDER-LEFT: #cccccc 2px solid; BACKGROUND-COLOR: #e7e7e9; WIDTH: 520px; DISPLAY: none; HEIGHT: 60px; BORDER-TOP: #cccccc 2px solid; TOP: -15px; BORDER-RIGHT: #cccccc 2px solid' id=b1>..."); 
			out.println("</DIV></TD></TR></TABLE>");
		}
		
/*
* 
* <TABLE>
<TBODY>
<TR>
<TD><BR></TD></TR>
<TR>
<TD width=525>
<TABLE width=525>
<TBODY></TBODY></TABLE>
<TABLE width=525>
<TBODY>
<TR>
<TD onclick=javascript:clickd(this) width=120>Solution Team lead :</TD>
<TD width=405>
<DIV style="COLOR: black; CURSOR: hand; TEXT-DECORATION: underline" id=1 onclick=javascript:clickd(this)>Srinivas Vanamala</DIV></TD></TR></TBODY></TABLE>
<TABLE width=575>
<TBODY>
<TR>
<TD width=275>Location : Remote-Asia</TD>
<TD width=250>Customer : Hewlett Packard</TD>
<TD width=50><INPUT id=DB050022C11A2E3985257A62003B1380 class=lotusBtn onclick=javascript:removeAdopt(this) value=Remove type=button></TD>
<DIV style="DISPLAY: none" id=td1>CN=Srinivas Vanamala/OU=SG/OU=Asia/O=Celestica</DIV></TR></TBODY></TABLE></TR></TBODY></TABLE>
<TABLE width=525 height=15>
<TBODY>
<TR bgColor=#a2a1a6>
<TD>Process</TD>
<TD>Primary Benefit</TD>
<TD>Benefit Results</TD>
<TD>Days to Implement</TD>
<TD>Adopted Feedback</TD>
<TD>Date Implemented</TD></TR>
<TR bgColor=#ebf1d5>
<TD width=75>Greentech</TD>
<TD width=100>Quality</TD>
<TD width=75>121 DPU</TD>
<TD width=75>1</TD>
<TD width=100>Very easy to implement</TD>
<TD width=100>20120831</TD></TR></TBODY></TABLE>

<TABLE width=525>
<TBODY>
<TR>
<TD width=275><B>Continuous Improvement Comments: </B></TD></TR>
<TR>
<TD width=275></TD></TR></TBODY></TABLE>
<DIV style="BORDER-BOTTOM: #cccccc 2px solid; BORDER-LEFT: #cccccc 2px solid; BACKGROUND-COLOR: #e7e7e9; WIDTH: 520px; DISPLAY: none; HEIGHT: 60px; BORDER-TOP: #cccccc 2px solid; TOP: -15px; BORDER-RIGHT: #cccccc 2px solid" id=b1>... 
</DIV>
</TD>
</TR>
</TABLE>
*/
		
	}
}
